---
title: "Clipboard"
enterprise: true
---

You can copy and paste items to and from the grid using the system clipboard.

## How to copy

Copying from the grid is **enabled by default** for enterprise users. To copy your selection to the system clipboard, you can use the keybind {% kbd "^ Ctrl" /%}+{% kbd "C" /%}, or right click on a cell and select 'Copy' from the context menu. Unless [Range Selection](./range-selection) or [Row Selection](./row-selection) is enabled, you will only be copying from the currently focused cell.

When copying multiple cells, the contents will be copied in an Excel compatible format, with fields
separated by a `\t` (tab) character.

## Copying Cell Ranges

When [Cell Ranges](./range-selection) are enabled by setting `gridOptions.enableRangeSelection=true`, copying will copy the Cell Range's content to your clipboard. Select a range by clicking on a cell and dragging with the mouse, then copy with the {% kbd "^ Ctrl" /%}+{% kbd "C" /%} keybind.

Multiple cell ranges can be selected at once using {% kbd "^ Ctrl" /%} and dragging with the mouse. When copying, all ranges will be copied to the clipboard. Note that the relative positions of multiple ranges is not preserved when copying, they are stacked vertically in the clipboard.

The column headers can be copied to the clipboard in addition to the cell contents by enabling the option `copyHeadersToClipboard`.

{% apiDocumentation source="grid-options/properties.json" section="clipboard" names=["copyHeadersToClipboard"] /%}

In the below example `copyHeadersToClipboard` has been enabled, try:

* Select a cell range with click & drag
* Copy with {% kbd "^ Ctrl" /%}+{% kbd "C" /%}
* Paste into an external program / text editor, note that the column headers were also copied.

{% gridExampleRunner title="Copying Cell Ranges" name="copy-range" /%}

## Copying Rows

When [Row Selection](./row-selection) is enabled by setting `gridOptions.rowSelection` to either `"single"` or `"multiple"`, then copying while a row is selected will add the whole row's contents to your clipboard.

The below example demonstrates copying rows:

* Please select one or more rows in the example below and press CTRL+C
* Paste copied content in a text editor
* Note pasted content includes all selected rows

{% gridExampleRunner title="Copying Rows" name="copy-row" /%}

If you want to use row selection for another purpose and wish to copy the focused cell instead of selected rows, you can disable copying rows by setting
`gridOptions.suppressCopyRowsToClipboard=true`.

{% apiDocumentation source="grid-options/properties.json" section="clipboard" names=["suppressCopyRowsToClipboard"] /%}

The below example demonstrates copying the focused cell only when using row selection:

* Please select one or more rows in the example below and press CTRL+C
* Paste copied content in a text editor
* Note pasted content includes focused cell only

{% gridExampleRunner title="Suppress Copying Rows" name="suppress-copy-row" /%}

## Mixed Copying Cell Ranges & Rows

The copy operation copies the selected content in the following order of precedence:

1. Cell Ranges (if [Range Selection](./range-selection) is enabled)
1. Row Selection (if [Row Selection](./row-selection) is enabled and `suppressCopyRowsToClipboard` is **not** enabled)
1. Focused Cell

When both range selection and row selection are enabled, the default behaviour of copying ranges over copying rows can make it impossible for users to copy rows (as the selected cell range is copied by default). Enabling the grid option `gridOptions.suppressCopySingleCellRanges=true` makes it possible to copy the selected rows when only a single cell is selected via range selection.

{% apiDocumentation source="grid-options/properties.json" section="clipboard" names=["suppressCopySingleCellRanges"] /%}

In this mode, when multiple cells are selected via range selection, the cell range is copied and not the selected rows. This behaviour is not enabled by default since it can be confusing for the copy behaviour to change depending on how much is selected.

The below example has range selection, row selection and `suppressCopySingleCellRanges` enabled.

* Select a range by clicking & dragging on a cell.
* Copy with {% kbd "^ Ctrl" /%}+{% kbd "C" /%}, paste into a text editor, observe that the range was copied.
* Deselect this range by clicking on any cell
* Select one or more rows by moving focus with the arrow keys and pressing the {% kbd "␣ Space" /%} key to toggle the row's selection.
* Copy with {% kbd "^ Ctrl" /%}+{% kbd "C" /%}, paste into a text editor and observe that the rows were copied.

{% gridExampleRunner title="Copying Mixed Ranges & Rows" name="copy-mixed" /%}

## Custom Clipboard Interaction

If you want to do the copy to clipboard yourself (i.e. not use the grid's clipboard interaction) then implement the callback `sendToClipboard(params)`. Use this if you are in a non-standard web container that has a bespoke API for interacting with the clipboard. The callback gets the data to go into the clipboard, it's your job to call the bespoke API.

The example below shows using `sendToClipboard(params)`, but rather than using the clipboard, demonstrates the callback by just printing the data to the console.

{% gridExampleRunner title="Controlling Clipboard Copy" name="custom" /%}

## Copying via the API

You can use the Grid API methods: `copySelectedRowsToClipboard(...)` and `copySelectedRangeToClipboard(...)`
to copy rows or ranges respectively, these API calls take optional parameters to enable copying column and group headers.

{% apiDocumentation source="grid-api/api.json" section="clipboard" names=["copySelectedRangeToClipboard", "copySelectedRowsToClipboard"] /%}

## How to Cut

Cut from the grid is **enabled by default** for enterprise users. To cut your selection to the system clipboard, you can use the keybind {% kbd "^ Ctrl" /%}+{% kbd "X" /%}, or right click on a cell and select 'Cut' from the context menu. Unless [Range Selection](./range-selection) or [Row Selection](./row-selection) is enabled, you will only be copying from the currently focused cell.

The cut operations will work exactly the same as the copy operations, with the addition that data will be removed from the grid afterwards, so the cut operations will use the same properties described above to customise the `copy` process.

## Disabling Cut

Since `Cut` is a destructive process, the `suppressCutToClipboard` property was added to the Grid Options.

```js {% frameworkTransform=true %}
const gridOptions = {
    suppressCutToClipboard: true
}
```

This is demonstrated in the example below. Note the following:

* Selecting a cell and pressing {% kbd "^ Ctrl" /%}+{% kbd "X" /%} will not `copy` or `cut` the data.
* The context menu will not show an option to `Cut`.

{% gridExampleRunner title="Clipboard Suppress Cut" name="suppress-cut" /%}

## How to Paste

Paste is enabled by default in the enterprise version and is possible as long as the cells you're pasting into are [editable](./cell-editing) (non-editable cells cannot be modified, even with a paste operation). You can paste using the keybind {% kbd "^ Ctrl" /%}+{% kbd "V" /%} while focus is on the grid.

The behaviour of paste changes depending whether you have a single cell or a range selected:

* When a **single cell is selected**. The paste will proceed starting at the selected cell if multiple cells are to be pasted.
* When a **range of cells selected**. If the selected range being pasted is larger than copied range, it will repeat if it fits evenly, otherwise it will just copy the cells into the start of the range.

{% note %}
The 'paste' operation in the context menu is not possible and hence always disabled.
It is not possible because of a browser security restriction that JavaScript cannot
take data from the clipboard without the user explicitly doing a paste command from the browser
(e.g. {% kbd "^ Ctrl" /%}+{% kbd "V" /%} or from the browser menu). If JavaScript could do this, then websites could steal
data from the client via grabbing from the clipboard maliciously. The reason why the grid keeps
the paste in the menu as disabled is to indicate to the user that paste is possible and it provides
the shortcut as a hint to the user. This is also why the API cannot copy from clipboard.
{% /note %}

## Disabling Paste

You can turn paste operations off for the entire grid, by setting the grid property `suppressClipboardPaste=true`.

Or you can disable pasting for a specific column or cell by setting the property `suppressPaste` on the column definition. This can be a boolean or a function (use a function to specify for a particular cell, or boolean for the whole column).

{% apiDocumentation source="column-properties/properties.json" section="columns" names=["suppressPaste"] /%}

## Processing Pasted Data

The clipboard data will be processed by default [Using the Value Formatter for Export](./value-formatters/#use-value-formatter-for-export) to format the cells when copied, and [Using the Value Parser for Import](./value-parsers/#use-value-parser-for-import) to format the cells when pasted.

It is possible to override this behaviour specifically for the clipboard. This can be done either on individual cells or the whole paste operation.

### Processing Individual Cells

The interfaces and parameters for processing individual cells are as follows:

{% apiDocumentation source="grid-options/properties.json" section="clipboard" names=["processCellForClipboard", "processHeaderForClipboard", "processGroupHeaderForClipboard", "processCellFromClipboard"] /%}

These three callbacks above are demonstrated in the example below. Note the following:

* When cells are copied to the clipboard, values are prefixed with 'C-'. Cells can be copied by dragging a range with the mouse and hitting {% kbd "^ Ctrl" /%}+{% kbd "C" /%}.
* When cells are pasted from the clipboard, values are prefixed with 'Z-'. Cells can be pasted by hitting {% kbd "^ Ctrl" /%}+{% kbd "V" /%}.
* When headers are copied to the clipboard, values are prefixed with 'H-'. Headers can be copied by using the context menu.
* When group headers are copied to the clipboard, values are prefixed with 'GH-'. Headers can be copied by using the context menu.

{% gridExampleRunner title="Example Process" name="process" /%}

### Processing Data from Clipboard

To have complete control of processing clipboard data when pasting, you can use the callback below:

{% apiDocumentation source="grid-options/properties.json" section="clipboard" names=["processDataFromClipboard"] /%}

The following example shows custom code to process the data from the clipboard:

* The cells are coloured based on the colour that the cell content starts with
* Copy a cell range in the grid which includes a cell value that starts with `Red`. Pasting into the grid will paste a custom 4x4 cell grid.
* Copy a cell range in the grid which includes a cell value that starts with `Yellow` and **doesn’t** include any `Red` cell values. Pasting this copied cell range will cancel the paste action and not paste anything
* Any other copied cell data will be pasted as-is

{% gridExampleRunner title="Example Process Data" name="process-all" /%}

### Pasting New Rows at the Bottom of the Grid

By default, when pasting multiple rows near the last record shown in the grid, any rows exceeding the total number of rows shown in the grid will not be pasted.

In order to insert all the copied rows in the grid, a custom `processDataFromClipboard` function is needed to add the necessary number of new rows using the [Transaction Update API](./data-update-transactions/#transaction-update-api).

The example below uses a custom `processDataFromClipboard` function to add new rows to the grid, to fit all the copied rows:

* Select the top 3 rows in the grid using {% kbd "⇧ Shift" /%} + click
* Press {% kbd "^ Ctrl" /%}+{% kbd "C" /%} to copy the selected rows
* Select the `Ryan Lochte` cell on the last row and press {% kbd "^ Ctrl" /%}+{% kbd "V" /%} to paste the copied rows
* Notice that the `Ryan Lochte` row has been overwritten and 2 extra rows are created at the bottom of the grid to accommodate the additional 2 rows pasted

{% gridExampleRunner title="Paste New Rows" name="pasting-extra-rows" /%}

### Read Only Edit

When the grid is in [Read Only Edit](./value-setters/#read-only-edit) mode the `Clipboard` will not update the data inside the grid. Instead the grid fires `cellEditRequest` events allowing the application to process the update request.

{% apiDocumentation source="grid-events/events.json" section="editing" names=["cellEditRequest"] /%}

The example below will show how to update cell value combining the `Clipboard` with `readOnlyEdit=true`.

{% gridExampleRunner title="Clipboard - ReadOnlyEdit" name="read-only-edit" /%}

## Changing the Delimiter for Copy & Paste

By default, the grid will use `\t` (tab) as the field delimiter. This is to keep the copy / paste compatible with Excel. If you want another delimiter then you can set the property `gridOptions.clipboardDelimiter` to a value of your choosing.

## Using the Browser's Text Selection

The grid's selection and copy features replace the built-in browser behaviour for selecting and copying text. If you want to use the normal browser behaviour instead, you should set `enableCellTextSelection=true` in the gridOptions. Note the following:

* When `enableCellTextSelection=true`, pressing {% kbd "^ Ctrl" /%}+{% kbd "C" /%} doesn’t copy the focused cell value, but only the selected text inside the grid cell. When using AG Grid Enterprise, the user can copy the entire cell value by right-clicking the grid cell to show the [context menu](./context-menu/#top) and clicking the any of the Copy menu items.

* When `enableCellTextSelection=true`, the option `ensureDomOrder=true` needs to be set for correct accessibility support. See [Ensure DOM Element order](./accessibility/#ensure-dom-element-order).

{% note %}
This is not an enterprise config and can be used at any time to enable cell text selection.
{% /note %}

See this behavior shown in the example below:

* Focus a grid cell and press {% kbd "^ Ctrl" /%}+{% kbd "C" /%}. The cell value will not be copied because no text is selected.

* Click a cell and drag across its value to select the text. Press {% kbd "^ Ctrl" /%}+{% kbd "C" /%} and the value will be copied.

* This sample is using AG Grid Community version, so the context menu is not available to copy the focused cell value. In AG Grid Enterprise the context menu will be available to copy the entire focused cell value without having to select it as text.

{% gridExampleRunner title="Using Browser text selection" name="cellTextSelection" /%}

## Clipboard Events

The following events are relevant to clipboard operations:

{% apiDocumentation source="grid-events/events.json" section="clipboard" names=["cutStart","cutEnd","pasteStart","pasteEnd"] config={"overrideBottomMargin":"0rem"} /%}

{% apiDocumentation source="grid-events/events.json" section="editing" names=["cellValueChanged"] config={ "hideMore":false} /%}

For a cut or paste operation the events will be fired as:

1. One `cutStart`/`pasteStart` event.
1. Many `cellValueChanged` events.
1. One `cutEnd`/`pasteEnd` event.

If the application is doing work each time it receives a `cellValueChanged`, you can use the `cutStart`/`pasteStart` and `cutEnd`/`pasteEnd` events to suspend the applications work and then do the work for all cells impacted by the cut/paste operation after the cut/paste operation.

There are no events triggered by copy to clipboard as this does not change the grid's data.

{% gridExampleRunner title="Clipboard Events" name="clipboard-events" /%}
